import { message, Modal } from 'ant-design-vue';

/**
 *
 * @param content 提示内容
 * @param title 提示标题
 */
export function PopMsg(
  content: string,
  title: string,
  type: 'confirm' | 'error' | 'info' | 'success' | 'warn' | 'warning',
) {
  return new Promise((reslove, reject) => {
    switch (type) {
      case 'confirm': {
        Modal.confirm({
          content,
          onCancel() {
            reject(new Error('已取消'));
          },
          onOk() {
            reslove(true);
          },
          title,
        });
        break;
      }
      case 'error': {
        Modal.error({
          content,
          title,
        });
        break;
      }
      case 'info': {
        Modal.info({
          content,
          title,
        });
        break;
      }
      case 'success': {
        Modal.success({
          content,
          title,
        });
        break;
      }
      case 'warning': {
        Modal.warning({
          content,
          title,
        });
        break;
      }
      default: {
        Modal.confirm({
          content,
          onCancel() {
            reject(new Error('已取消'));
          },
          onOk() {
            reslove(true);
          },
          title,
        });
        break;
      }
    }
  });
}

export function messageSuccess(content: string) {
  message.success({
    content,
  });
}
export function messageError(content: string) {
  message.error({
    content,
  });
}
